package envs

import (
	"../luahelper"
	lua "github.com/yuin/gopher-lua"
	"os"
)

func Register_4lua(l *lua.LState) {
	l.SetGlobal("Env", l.SetFuncs(l.NewTable(), map[string]lua.LGFunction{
		"Get": Get_4lua,
	}))
}

func Get_4lua(l *lua.LState) int {
	name := l.ToString(1)

	if name == "" {
		return luahelper.PushErrorMessage(l, "not found name")
	}

	value := os.Getenv(name)

	if value == "" {
		return 0
	}

	l.Push(lua.LString(value))
	return 1
}
